<template>
	<view class="home">
		<view class="device-status_bar with-blue"></view>
		<view class="big-header" style="">
			<view class="search zt">
				<view class="place" @tap="goLocation">
					<text style="margin-right: 5px">{{
            address.city || '定位失败'
          }}</text>
					<image src="../../static/client/triangleWhiteDown.png" style="width: 10px; height: 10px"
						class="SelectIcon"></image>
				</view>
				<icon type="search" size="12" color="#FFFFFF" />
				<input type="search" disabled style="min-width: 100px" placeholder="请输入园区名或位置搜索" placeholder-style="color:#fff"
					@tap="goSearch" />
			</view>
		</view>

		<view style="border-radius: 10px">
			<swiper :circular="true" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
				indicator-active-color="#ffffff" class="swiper zt">
				<swiper-item class="swiperItems" v-for="item in swiperlist" :key="item.id">
					<view class="swiper-item" @click="goPreview(item)">
						<image :src="item.image" class="img"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- home页面 -->
		<view class="chat-messages-body">
			<view class="button-box-wrapper">
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="toListPage((displayBuildMode = false))">
					<view class="icon-img home-find-house" style=""></view>
					<view class="text">查看房源</view>
				</view>
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/myHousing')">
					<view class="icon-img home-my-house" style=""></view>
					<view class="text">我的房源</view>
				</view>
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/expandHousing')">
					<view class="icon-img home-add-house" style=""></view>
					<view class="text">拓房</view>
				</view>
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/customerList/customerList')">
					<view class="icon-img home-my-consumer" style=""></view>
					<view class="text">我的私客</view>
				</view>
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/private/private')">
					<view class="icon-img home-public-consumer" style=""></view>
					<view class="text">公客</view>
				</view>
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/customerDataEnter')">
					<view class="icon-img home-add-consumer" style=""></view>
					<view class="text">客户录入</view>
				</view>
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/follow/follow')">
					<view class="icon-img home-add-collect" style=""></view>
					<view class="text">关注</view>
				</view>
<!-- 				<view v-if="userRightDetail.goodsRelease.right" class="button-box" @click="go('/test/developing')">
					<view class="icon-img my-house-source" style=""></view>
					<view class="text">会议室申请</view>
				</view> -->
				<view v-if="userRightDetail.goodsRelease.right" class="button-box" @click="go('/receiveHouse/details/details?id=-1'+ '&state=待申请')">
					<view class="icon-img home-receive" style=""></view>
					<view class="text">办理交房</view>
				</view>
				<view v-if="userRightDetail.renewal.contractCommRight" class="button-box" @click="go('/renewHouse/details/details?id=-1'+ '&state=待申请')">
					<view class="icon-img home-renewHouse" style=""></view>
					<view class="text">发起续租</view>
				</view>
				<view v-if="userRightDetail.goodsRelease.right" class="button-box" @click="go('/vacantHouseCheck/history/history')">
					<view class="icon-img home-vcantHouse" style=""></view>
					<view class="text">空置房管理</view>
				</view>
				<view v-if="userRightDetail.decoration.engCommRight" class="button-box" @click="go('/meter/history/history')">
					<view class="icon-img meter-cc-add" style=""></view>
					<view class="text">水电表抄送</view>
				</view>
<!-- 				<view v-if="userRightDetail.invoice.finanCommRight" class="button-box" @click="go('/test/developing')">
					<view class="icon-img my-house-source" style=""></view>
					<view class="text">租金预警管理</view>
				</view>
				<view v-if="userRightDetail.invoice.finanCommRight" class="button-box" @click="go('/test/developing')">
					<view class="icon-img my-private-customer" style=""></view>
					<view class="text">租户费用统计</view>
				</view> -->
<!-- 				<view v-if="userRightDetail.invoice.finanCommRight" class="button-box" @click="go('/test/developing')">
					<view class="icon-img expand-house-logo" style=""></view>
					<view class="text">综合报表统计</view>
				</view> -->
				<view v-if="userRightDetail.invoice.finanCommRight" class="button-box" @click="go('/meterFinance/history/history')">
					<view class="icon-img meter-cc" style=""></view>
					<view class="text">水电费录入</view>
				</view>
				<view v-if="userRightDetail.invoice.finanCommRight" class="button-box" @click="go('/onlinePay/details/details?id=-1'+ '&state=待申请')">
					<view class="icon-img home-onlinePay" style=""></view>
					<view class="text">发起缴费通知</view>
				</view>
<!-- 				<view v-if="userRightDetail.invoice.finanCommRight" class="button-box" @click="go('/test/developing')">
					<view class="icon-img customer-record-logo" style=""></view>
					<view class="text">账单查询</view>
				</view> -->
<!-- 				<view class="button-box" @click="go('/test/developing')">
					<view class="icon-img expand-house-logo" style=""></view>
					<view class="text">合同综合管理</view>
				</view>
				<view class="button-box" @click="go('/test/developing')">
					<view class="icon-img my-house-source" style=""></view>
					<view class="text">自动续租配置</view>
				</view> -->
				<view v-if="userRightDetail.knotCommission.primeAuth == 4 || userRightDetail.knotCommission.primeAuth == 3" class="button-box" @click="go('/knotCommission/details/details?id=-1'+ '&state=待申请')">
					<view class="icon-img home-knotCommission" style=""></view>
					<view class="text">申请结佣</view>
				</view>
				<view class="button-box" @click="go('/order/orderHome')">
					<!-- <view class="jiao"></view> -->
					<i v-if="pendingTotal > 0" class="tip"></i>
					<view class="icon-img home-order" style=""></view>
					<view class="text">我的工单</view>
				</view>
				<view class="button-box" style="opacity: 0"> </view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		appMixin
	} from "../../util/reuse"
	import {
		d_uniShowToast,
		CURRENT_USER_KEY,
		ROUTER_OBJ,
		SHORT_TOAST_DURATION,
		TOAST_DURATION,
		uniNavigate
	} from "../../util/misc"
	import {
		uniHideLoading
	} from "../../util/commonFuncs"
	import {
		authRouterGuard,
		homeInitLocation,
		uniRedirect,
		uniSetToken,
		uniGetStorageSync
	} from '../../util/funcs';
	import {
		uniRequestP,
		tokenRequestP,
		ONLINE_SERVER_ADDRESS_BASE_2
	} from '../../util/network.js'

	export default {
		mixins: [appMixin],
		components: {},
		data() {
			return {
				address: {
					province: '',
					city: '',
					district: '',
				},
				swiperlist: [],
				flag:1,
				userRightDetail:"",
				pendingData:"",
				token:'',
				pendingTotal:0,
			}
		},

		onLoad: async function() {
			authRouterGuard(this).then(async (res) => {
				this.getBanners()
				this.address = await this.initLocation()
			})
			
		},

		onShow() {
			this.userRightDetail = uni.getStorageSync("userRight")
			this.pendingData = uni.getStorageSync("pendingData")
			this.token = uni.getStorageSync('token')
			this.createSetInterval()
			console.log(this.userRightDetail)
		},
		onUnload() {
			this.stopSetInterval()
		},
		methods: {
			go(page) {
				// uniNavigate(page)
				console.log('ceshi',this.$data)
				console.log('asd',this.$store.state.token)
				//if (this.$store.state.token) {
				if (true) {
					uniNavigate(page)
				} else {
					uni.showToast({
						title: "请登录",
						position: 'top',
						icon: 'none',
						duration: TOAST_DURATION
					});
					setTimeout(() => {
						uniRedirect('/login/login');
					}, TOAST_DURATION)
				}
			},
			
			// true 盘源列表, false 房源列表,
			toListPage(displayBuildMode) { 
				if (!this.address.city) {
					d_uniShowToast({
						title: '请先选择您的定位'
					})
					setTimeout(() => {
						uniNavigate('/location/location')
					}, SHORT_TOAST_DURATION)
					return
				}
				uni.setStorageSync(ROUTER_OBJ, {
					displayBuildMode: displayBuildMode, // true 盘源列表, false 房源列表
				})
				uniNavigate('/listPage/listPage')
			},
			
			goLocation() {
				uniNavigate('/location/location')
			},
			
			goSearch() {
				uni.navigateTo({
					url: `/pages/search/search`,
					fail: function(res) {
						console.log(res)
					}
				});
			},
			
			getBanners() {
				this.$uniRequest('/business',{},'POST',false).then((data) => {
					this.swiperlist = data.data;
					console.log('test')
				})
				// uni.request({
				// 	url: `${this.$http}/api/app/business`,
				// 	method: 'POST',
				// 	success: (res) => {
				// 		uniHideLoading()
				// 		// console.log('swiper',res.data)
				// 		this.swiperlist = res.data.data;
				// 	},
				// 	fail: (res) => {
				// 		console.log('swiper', res.data)
				// 		uniHideLoading()
				// 	}
				// })
			},
			getPending(){
				let _this = this
				// console.log('pendingdata',this.pendingData)
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE_2}/message/get-pending`,
					header: {
						'Authorization': this.token,
					},
					data:this.pendingData,
					method:'POST',
					success: function (res) {
						// console.log('待处理',res)
						if(res.data.code == 200){
							_this.$pendingObj.setPendingObj(res.data.data)
							_this.pendingTotal = _this.$pendingObj.pendingObj.total
						}
					}
				})
			},
		// 开启轮询  如果存在则先销毁定时器后重新开启
			createSetInterval() {
			  this.stopSetInterval()
			  let _this = this
			  this.$myTimer.setTimer(setInterval(() => {
				_this.getPending()
			  }, 1000))
			},
			// 关闭轮询
			stopSetInterval() {
			  if (this.$myTimer.myTimer) {
				clearInterval(this.$myTimer.myTimer)
				this.$myTimer.setTimer(null)
			  }
			}
		},
	}
</script>

<style scoped lang="scss">
	@import '../../assets/styles/global';
	.home{
		height: 100%;
		overflow-y: scroll;
	}
	
	.big-header {
		background-image: linear-gradient(180deg, #2667b9 0%, #113e7e 100%);
		padding-top: 20px;
		height: 388rpx;
		z-index: 5; // 要比滑下来的东西高一点
	}

	.swiper {
		background-color: whitesmoke;
		z-index: 1;
		width: 686rpx;
		height: 400rpx;
		border-radius: 15px;
		margin-top: -242rpx;
	}

	.search {
		color: #ffffff;
		display: flex;
		height: 40px;
		line-height: 40px;
		background-color: #487ec4;
		border-radius: 30px;
		padding: 0px 1em;
		flex-wrap: inherit;
		margin-bottom: 30rpx;
	}

	.chat-messages-body {
		position: relative;
		width: 100vw;
		padding: 30rpx 30rpx 0;

		.button-box-wrapper {
			display: flex;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.button-box {
				@include center;
				flex-direction: column;

				.icon-img {
					width: 80rpx;
					height: 80rpx;
					@include contain-no-repeat-center;
					margin-bottom: 20rpx;
				}

				.my-private-customer {
					background-image: url('../../static/images/home/wodesikIcon.png');
				}

				.customer-record-logo {
					background-image: url('../../static/images/home/kehuluru_icon@3x.png');
				}

				.expand-house-logo {
					background-image: url('../../static/images/home/tuofang_icon@3x.png');
				}

				.follow-logo {
					background-image: url('../../static/images/home/guanzhu_icon@3x.png');
				}

				.my-house-source {
					background-image: url('../../static/images/home/wodefangyaun_icon@3x.png');
				}

				.public-customer {
					background-image: url('../../static/images/home/gongke_icon@3x.png');
				}
				
				.meter-cc {
					background-image: url('../../static/order/metercc.png');
				}

				.meter-cc-add {
					background-image: url('../../static/order/addmetercc.png');
				}

				.home-onlinePay {
					background-image: url('../../static/order/home-onlinePay.png');
				}
				
				.home-receive {
					background-image: url('../../static/order/home-receive.png');
				}
				
				.home-renewHouse {
					background-image: url('../../static/order/home-renewHouse.png');
				}
				
				.home-vcantHouse {
					background-image: url('../../static/order/vcantHouse.png');
				}
				
				.home-order {
					background-image: url('../../static/order/home-order.png');
				}
				
				.home-add-collect {
					background-image: url('../../static/order/home-add-collect.png');
				}
				
				.home-add-consumer {
					background-image: url('../../static/order/home-add-consumer.png');
				}
				
				.home-add-house {
					background-image: url('../../static/order/home-add-house.png');
				}
				
				.home-find-house {
					background-image: url('../../static/order/home-find-house.png');
				}
				
				.home-my-consumer {
					background-image: url('../../static/order/home-my-consumer.png');
				}
				
				.home-find-house {
					background-image: url('../../static/order/home-find-house.png');
				}
				
				.home-my-house {
					background-image: url('../../static/order/home-my-house.png');
				}
				
				.home-public-consumer {
					background-image: url('../../static/order/home-public-consumer.png');
				}
				
				.home-knotCommission {
					background-image: url('../../static/order/home-knotCommission.png');
				}
				
				.text {
					height: 48rpx;
					font-family: PingFangSC-Medium;
					font-size: 28rpx;
					color: #323233;
				}
				.jiao, .desc {
					position: relative;
					top:0;
					left: 105rpx;
				}
				.jiao {
					line-height: 18px;
					width: 18px;
					height: 18px;
					// transform: rotate(-50deg);
					border-radius: 50%;
					// -webkit-transform: rotate(-50deg);
					// -moz-transform: rotate(-50deg);
					// -ms-transform: rotate(-50deg);;
					top: -15px;
					right: -4px;
					background-color: #d51414;
					padding:0;
				}
				.desc {
					top: -30rpx;
				}
				width: 210rpx;
				height: 210rpx;
				background-color: #ffffff;
				/*background-color: red;*/
				box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(26, 79, 150, 0.14);
				border-radius: 8rpx;
				border: solid 1rpx #c8c9cc;
				margin-bottom: 30rpx;
			}
		}
	}

	.SelectIcon {
		width: 10px;
		height: 10px;
	}

	.srollView {
		white-space: nowrap;
	}

	.rollViewItem {
		display: inline-block;
	}

	.place {
		font-size: 16px;
		margin-right: 5px;
		max-width: 120px;
		white-space: nowrap;
	}

	.titleMargin {
		margin: 30px 0 20px 15px;
		font-size: 18px;
	}

	.recommendHouse {
		padding: 10px 0;
		border-bottom: 1px solid #f5f6f7;
		display: flex;
	}

	.recommendHouse:nth-child(1) {
		padding-top: 0px;
	}

	.img {
		width: 100%;
	}

	.swiperItems {
		border-radius: 10px;
	}

	.search>icon {
		margin-left: 5px;
		position: relative;
		top: 1px;
	}

	.search>option {
		border: none;
		outline: none;
		background: #487ec4;
	}

	.search>select {
		color: #ffffff;
		padding-left: 1em;
		font-size: 16px;
		border: none;
		outline: none;
		border: 0;
		background: transparent;
	}

	.search>input {
		height: 40px;
		width: 70%;
		margin-left: 5px;
	}

	.search>input::-webkit-input-placeholder {
		color: #ffffff !important;
	}

	.fl {
		float: left;
	}

	.fr {
		float: right;
	}

	.fixed:after {
		content: '';
		display: block;
		clear: both;
	}
	.tip {
		width:10px;
		height:10px;
		line-height:20px;
		font-size:10px;
		color:#fff;
		text-align:center;
		background-color:#f00;
		border-radius:50%;
		margin-top: -15rpx;
		margin-left: 150rpx;
	}
</style>
